$(function () {
    $("#i1").keyup(function () {
        var shuru=$("#i1").val();
        $.ajax({
            type:"get",
            url:"getMess.do",
            data:"shuru="+shuru,
            success:function (data) {
                $("#d1").html("");
                console.log("显示信息:"+JSON.stringify(data))
                if(shuru!=""){
                    $("#d1").attr("hidden",false);
                    $("#d1").append("<table border='1px' id='t1'><tr><td>客户ID&nbsp&nbsp&nbsp&nbsp</td><td>客户名称&nbsp&nbsp&nbsp&nbsp</td><td>客户手机&nbsp&nbsp&nbsp&nbsp</td><td>客户电话&nbsp&nbsp&nbsp&nbsp</td></tr></table>")
                    for (var i=0;i<data.length;i++){
                        $("#t1").append("<tr class='tr1'><td>"+data[i].custID+"</td><td>"+data[i].custName+"</td><td>"+data[i].custMobile+"</td><td>"+data[i].custTel+"</td></tr>")
                    }
                }else{
                    $("#d1").attr("hidden",true);

                }
            }
         })

    })


$("#i1").blur(function () {
    $("#d1").html("")
})

    $("#end").click(function () {
         var billID=$("#span1").html();
         window.location="http://localhost:10000/ruku/jiesuan.do?billID="+billID;
    })



     $("#lizi,#qita").keyup(function () {
         //力资费
         var billFeeTruckage=$("#lizi").val();
          //其他费用
         var billFeeOther=$("#qita").val();
         //库存费
         var billFeeStore=$("#kucun").val();
        console.log("力资费"+billFeeTruckage)
        console.log("其他费用"+billFeeOther)
        console.log("库存费"+billFeeStore)
        $("#hejiyingshou").val(((billFeeStore*1.0)*30)+(billFeeTruckage*1.0)+(billFeeOther*1.0));
        $("#hejishishou").val(((billFeeStore*1.0)*30)+(billFeeTruckage*1.0)+(billFeeOther*1.0));
    })









})

function startyanhuo() {
    let flag=0
    let billIdtd = document.getElementsByName("billId");
    let custNametd = document.getElementsByName("custName");
    let danxuantd = document.getElementsByName("danxuan");
    for( let i=0;i<danxuantd.length;i++){
        if(danxuantd[i].checked==true){
            window.location = "zhuangpan.do?billID="+billIdtd[i].innerHTML+"&&custName="+custNametd[i].innerHTML;
            flag=1
            break
        }
    }
    if(!flag){
        alert("必须选择一个")
    }
}

function selectAll() {
    var checkboxs=document.getElementsByName("choose");
    for (var i=0;i<checkboxs.length;i++) {
        var e=checkboxs[i];
        e.checked=!e.checked;
    }
}

function duoxuan() {
    let flag=0
    let duoxuan = document.getElementsByName("choose");
    for( let i=0;i<duoxuan.length;i++){
        if(duoxuan[i].checked==true){
            var billID=$("#span1").html();
            window.location="http://localhost:10000/ruku/jiesuan.do?billID="+billID;
            flag=1
            break
        }
    }
    if(!flag){
        alert("至少选择一项")
    }
}

function deleteMany() {
    let flag=0
    var detailsID = document.getElementsByName("detailsID");
    console.log(detailsID)

    let duoxuan = document.getElementsByName("choose");
    for( let i=0;i<duoxuan.length;i++){
        if(duoxuan[i].checked==true){
            window.location="http://localhost:10000/ruku/deleteMany.do?detailsID="+detailsID[i].innerHTML;
            alert("删除成功")
            flag=1
            break
        }
    }
    if(!flag){
        alert("至少选择一项")
    }



}
function feikong() {
    var kucun=$("#billFeeStore").val();
    var lizi=$("#billFeeTruckage").val();
    var qita=$("#billFeeOther").val();

    if(kucun=="" || lizi=="" || qita==""){
        alert("库存价、力资费、其他费用不能为空！")
        return false
    }else{
        return true
    }
}
